
;; 帮助
(use-package smex
  :ensure t
  :init
  (smex-initialize)
  :bind
  ("M-x" . 'smex)
)
(use-package which-key
  :ensure t
  :config
  (which-key-mode)
)

;; 代码补全
(use-package company-web
  :ensure t
)
(use-package company
  :ensure t
  :config
  (setq company-idle-delay 0.5)
  (setq company-auto-complete nil)
  (setq company-tooltip-limit 15)
  (setq company-tooltip-align-annotations t)
  (add-to-list 'company-backends '(company-tern company-css company-web-html company-yasnippet company-keywords company-files))
)
; 片段
(use-package yasnippet
  :ensure t
  :init
  (yas-global-mode t)
  :config
  (yas-reload-all)
)
; js 智能补全
(use-package company-tern 
  :ensure t
  :config
  (setq tern-command (append tern-command '("--no-port-file")))
)

;; terminal
(use-package terminal-here
  :ensure t
  :bind
  ("s-j" . 'terminal-here-launch)
)

;; 快速查找文件
(use-package find-file-in-project
  :ensure t
  :config
  (add-to-list 'ffip-prune-patterns "**/*.min.*")
  (add-to-list 'ffip-prune-patterns "**/*.map")
  (add-to-list 'ffip-prune-patterns "*/node_modules/*")
  :bind
  ("s-p" . 'find-file-in-project)
)

;; git
(use-package magit
  :ensure t
  :defer t
  :init
  (use-package magit-blame)
)

(use-package git-gutter-fringe+
  :ensure t
  :init
  (global-git-gutter+-mode t)
)

(use-package git-messenger
  :ensure t
)

;; 检查错误
(use-package flycheck
  :ensure t
  :config
  (flycheck-add-mode 'javascript-eslint 'web-mode)
)

;; 格式化
(use-package prettier-js
  :ensure t
  :defer t
  :config
  (setq prettier-js-args '(
    "--trailing-comma" "all"
    "--bracket-spacing" "true"
    "--single-quote" "true"
  ))
  (setq prettier-js-show-errors nil)
)
(use-package web-beautify
  :ensure t
  :defer t
  :bind
  ("C-c f" . 'web-beautify-html)
)

;; web
(use-package emmet-mode
  :ensure t
)
(use-package web-mode
  :ensure t
  :mode (
  ("\\.jsx\\'" . web-mode)
  ("\\.vue\\'" . web-mode)
  ("\\.sve\\'" . web-mode)
  ("\\.css\\'" . web-mode)
  ("\\.less\\'" . web-mode)
  ("\\.json\\'" . web-mode)
  ("\\.html?\\'" . web-mode)
  ("\\.[agj]sp\\'" . web-mode)
  ("\\.phtml\\'" . web-mode))
  :init
  (add-to-list 'auto-mode-alist '("\\.js\\'" . (lambda ()
    (web-mode)
    (flycheck-mode t)))
  )
  :config
  ; 缩进
  (setq web-mode-markup-indent-offset 2)
  (setq web-mode-css-indent-offset 2)
  (setq web-mode-code-indent-offset 2)
  (setq web-mode-attr-indent-offset 2)
  (setq web-mode-style-padding 2)
  (setq web-mode-script-padding 2)
  (setq web-mode-block-padding 0)
  ; 自动闭合标签
  (setq web-mode-enable-auto-pairing t)
  ; 当前元素高亮
  (setq web-mode-enable-current-element-highlight t)
  (add-hook 'web-mode-hook 'company-mode)
  (add-hook 'web-mode-hook 'tern-mode)
  (add-hook 'web-mode-hook 'emmet-mode)
)

(provide 'init-plugins)


